home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / du.arc / NGSIZES < prev    next >
Text File  |  1990-10-05  |  5KB  |  185 lines

  1. : '@(#) ngsizes 1.2 90/09/08 14:38:58'
  2. #
  3. # ngsizes - Generate disk usage summary for USENET newsgroups.
  4. #
  5. # Usage:
  6. #
  7. #   ngsizes [-D] [-b breakdown_list] [-t threshold]
  8. #
  9. #     -t  Specifies only groups using "threshold" or more disk blocks should
  10. #         be reported.  The default is defined by the "threshold" parameter
  11. #         below.
  12. #
  13. #     -b  Specifies how usage should be broken down versus age.  For example,
  14. #         saying "-b 0,7,14" will report usage in three columns:  the total
  15. #         usage, the usage by articles a week or older, and the usage by
  16. #         articles two weeks or older.  The default is defined by the
  17. #         "breakdown" parameter below.
  18. #
  19. #     -D  For debugging, the temporary files will be maintained.
  20. #
  21. # Site-Specific Definitions:
  22. #
  23. #   SPOOLDIR    Must point to your USENET spool directory.
  24. #   ACTIVE    Must point to your list of active USENET newsgroups.
  25. #   DU        Must point to the enhanced "du" command.
  26. #
  27. # Work Files:
  28. #
  29. #   $TMP.read    Readership statistics.
  30. #   $TMP.ngs    List of all newsgroups to check.
  31. #   $TMP.du    Disk usage for all directories in the news spool dir.
  32. #
  33. #
  34. # Sat Sep  8 14:34:56 1990 - Chip Rosenthal <chip@chinacat.Unicom.COM>
  35. #    Cleanup for distribution.
  36. # Tue Apr 17 21:50:58 1990 - Chip Rosenthal <chip@chinacat.Unicom.COM>
  37. #    Original composition.
  38. #
  39.  
  40. # Site-specific definitions.
  41. SPOOLDIR=/usenet/spool/news    # Points to the local news spool directory.
  42. ACTIVE=/usenet/lib/news/active    # Points to the local list of active newsgroups.
  43. DU=du                # Points to the enhanced "du" command.
  44.  
  45. # Default initializations.
  46. debug=0            # set nonzero to keep temp files around
  47. threshold=0        # show newsgroups greater than this (or '0' for all)
  48. breakdown=0,1,3,5,7,15    # breakdown usage by age, one col per number days given
  49.  
  50. TMP=/tmp/ngsz$$
  51. USAGE="usage: $0 [-b breakdown_list] [-t threshold]"
  52.  
  53. trap 'trap "" 0 ; rm -f $TMP.* ; exit 1' 1 2 3
  54. trap 'rm -f $TMP.* ; exit 0' 0
  55.  
  56. # Crack the command line options.
  57. if set -- `getopt 'Db:t:' $*` ; then
  58.     : getopt worked
  59. else
  60.     echo "$USAGE" 1>&2
  61.     exit 1
  62. fi
  63. while : ; do
  64.     case "$1" in
  65.     -D)  debug=1 ; shift ;;
  66.     -b)  breakdown="$2" ; shift ; shift ;;
  67.     -t)  threshold="$2" ; shift ; shift ;;
  68.     --)  shift ; break ;;
  69.     *)   echo "$USAGE" 1>&2 ; exit 1 ;;
  70.     esac
  71. done
  72. if [ $# -ne 0 ] ; then
  73.     echo "$USAGE" 1>&2
  74.     exit 1
  75. fi
  76.  
  77. # If debug is enabled, setup to keep temporary files around.
  78. if [ $debug -ne 0 ] ; then
  79.     trap '' 0 1 2 3
  80.     TMP=/tmp/ngsz
  81. fi
  82.  
  83. # Verify we can find the active file.
  84. if [ ! -r $ACTIVE ] ; then
  85.     echo "$0: file '$ACTIVE' not found or unreadable" 1>&2
  86.     exit 1
  87. fi
  88.  
  89. # Get a count of the readers for each newsgroup.
  90. # Output format will be "readership_count newsgroup_name"
  91. for newsrc in `awk -F: '{ print $6 "/.newsrc" }' /etc/passwd | sort -u` ; do
  92.     if [ -f $newsrc ] ; then
  93.     sed -n -e 's/:.*//p' $newsrc
  94.     fi
  95. done | sort | uniq -c > $TMP.read
  96.  
  97. # Extract the newsgroup names from the active file.
  98. # Output format will be "newsgroup_name"
  99. sed -e 's/[     ].*//' -e '/^$/d' $ACTIVE | sort -u > $TMP.ngs
  100.  
  101. # Scan the spool directory for disk usage.  Convert the newsgroup pathname
  102. # to a newsgroup name, and move it to the first field on the line.
  103. # Output format will be "newsgroup_name usage usage ..."
  104. if [ $debug -ne 0 -a -f $TMP.du ] ; then
  105.     : suppress scan for debugging
  106. else
  107.     $DU -ilr -c "$breakdown" $SPOOLDIR                \
  108.     | sed                            \
  109.         -e 's/^\(.*\)    \([^    ]*\)$/\2    \1/'    \
  110.         -e "s!$SPOOLDIR/!!"                    \
  111.         -e "s!/!.!g"                    \
  112.     | sort -u                        \
  113.         > $TMP.du
  114. fi
  115.  
  116.  
  117. # Generate the report.
  118. (
  119.     echo "BREAKDOWN $breakdown" | sed -e 's/,/ /g'
  120.     echo "THRESHOLD $threshold"
  121.     sed -e 's/^/READERS /' $TMP.read
  122.     join $TMP.du $TMP.ngs | sort -rn +1 | sed -e 's/^/NEWSGROUP /'
  123. ) | awk '
  124.  
  125. BEGIN {
  126.     LINE_WIDTH = 79    # maximum length of a line
  127.     NG_WIDTH = 26    # width of field to print newsgroup in
  128.     READR_WIDTH = 4    # width of field to print number of readers in
  129.     FRONT_FMT = "%-" NG_WIDTH "." NG_WIDTH "s" "%" READR_WIDTH "s"
  130. }
  131.  
  132. # Record "BREAKDOWN n1 n2 ..."
  133. #   Defines the format for the newsgroup usage lines.  Each "n" corresponds
  134. #   to one column in the newsgroup usage line, and specifies the age of
  135. #   articles which consume this amount of disk space.
  136. $1 == "BREAKDOWN" {
  137.     num_breakdn = NF - 1
  138.     FIELD_WIDTH = ( LINE_WIDTH - (NG_WIDTH+READR_WIDTH) ) / num_breakdn
  139.     if ( FIELD_WIDTH > 8 )
  140.     FIELD_WIDTH = 8
  141.     FIELD_FMT = "%" FIELD_WIDTH "s"
  142.     printf(FRONT_FMT,"newsgroup","read")
  143.     for ( i = 0 ; i < num_breakdn ; ++i )
  144.     printf(FIELD_FMT,sprintf("%ddays",$(i+2)))
  145.     printf("\n")
  146.     next
  147. }
  148.  
  149. # Record "THRESHOLD n"
  150. #   Indicates we only want to see newsgroups using "n" or more blocks.
  151. $1 == "THRESHOLD" {
  152.     threshold = $2
  153.     next
  154. }
  155.  
  156. # Record "READERS n ng"
  157. #   Indicates that newsgroup "ng" has "n" readers.
  158. $1 == "READERS" {
  159.     num_readers[$3] = $2
  160.     next
  161. }
  162.  
  163. # Record "NEWSGROUP ng n1 n2 ..."
  164. #   Indicates the disk usage of newsgroup "ng".  Each "n" specifies the
  165. #   diskspace used by articles "ndays" or older, where "ndays" is defined
  166. #   by the BREAKDOWN record.
  167. $1 == "NEWSGROUP" {
  168.     if ( $3 >= threshold ) {
  169.     if ( num_readers[$2] == "" )
  170.         num_readers[$2] = 0
  171.     printf(FRONT_FMT,$2,num_readers[$2])
  172.     for ( i = 0 ; i < num_breakdn ; ++i )
  173.         printf(FIELD_FMT,$(i+3))
  174.     printf("\n")
  175.     }
  176.     next
  177. }
  178.  
  179. { printf("ngsizes - bad line '%s'\n", $0) | "cat 1>&2" }
  180.  
  181. '
  182.  
  183. exit 0
  184.  
  185.